﻿using System;
using System.ServiceModel.Security;
using System.Threading;
using System.Windows.Forms;
using BlueMarineWindowsFormsClient.AuthenticateService;

namespace BlueMarineWindowsFormsClient
{
    public partial class frmUserInfo : Form
    {
        private static string userName;
        private readonly frmMain _main;


        public frmUserInfo(frmMain main)
        {
            InitializeComponent();
            _main = main;
            ViewInfo();
        }

        private void btnChangePassword_Click(object sender, EventArgs e)
        {
            userName = _main.UName;
            var t = new Thread(ThreadProc);
            t.Start();
            _main.Close();
            Close();
        }

        public static void ThreadProc()
        {
            Application.Run(new frmChangePassword(userName, ""));
        }

        private void ViewInfo()
        {
            var authen = new AuthenticateServiceClient("WSHttpBinding_IAuthenticateService")
                             {
                                 ClientCredentials =
                                     {
                                         UserName = {UserName = _main.UName, Password = _main.PWord},
                                         ServiceCertificate =
                                             {
                                                 Authentication =
                                                     {
                                                         CertificateValidationMode =
                                                             X509CertificateValidationMode.None
                                                     }
                                             }
                                     }
                             };

            Employee employee = authen.GetEmployee(_main.UName, _main.PWord);
            lblAccount.Text = employee.EmployeeAccount;
            lblName.Text = employee.EmployeeName;
            lblPosition.Text = employee.EmployeePosition;
            lblJobTitle.Text = employee.EmployeeJobTitle;
            lblD.Text = employee.EmployeeID.ToString();
            ptbEmpImage.Image = new ImageTool().ByteToImage(employee.EmployeeImage);
        }
    }
}